using System;
using System.Collections.Generic;

namespace SmartBoard.Core.Command
{
    //public class UIBinderCommand<T>:Command<T>,IUIBinderCommand<T>
    //{
    //    #region Private Fields
    //    private ICommandDescriptor _descriptor;
    //    private IDictionary<object,Func<object,bool,object>> _widgetsAndCanExecuteCallbackMapping;
    //    private IDictionary<object, Func<object, ICommandDescriptor, object>>  _widgetsAndInitializationCallbackMapping;
    //    #endregion

    //    #region Ctor
    //    public UIBinderCommand(Func<T, object> onExecute) : base(onExecute)
    //    {
    //        DoCtorWork();
    //    }

    //    public UIBinderCommand(Func<T, object> onExecute, Func<T, bool> onCanExecute) : base(onExecute, onCanExecute)
    //    {
    //        DoCtorWork();
    //    }

    //    private void DoCtorWork()
    //    {
    //        _widgetsAndInitializationCallbackMapping = new Dictionary<object, Func<object, ICommandDescriptor, object>>();
    //        _widgetsAndCanExecuteCallbackMapping = new Dictionary<object, Func<object, bool, object>>();
    //    }
    //    #endregion

    //    #region Implementation of IUIBinderCommand

    //    public ICommandDescriptor Descriptor
    //    {
    //        get { return _descriptor; }
    //    }

    //    public virtual void SetDescriptor(ICommandDescriptor descriptor)
    //    {
    //        _descriptor = descriptor;
    //        foreach (var initializationCallbackMapping in _widgetsAndInitializationCallbackMapping)
    //        {
    //            initializationCallbackMapping.Value(initializationCallbackMapping.Key, _descriptor);
    //        }
    //    }

    //    public void RegisterWidget<TW>(TW widget, Func<TW, ICommandDescriptor, object> initializationCallback, Func<TW, bool, object> canExecuteCallback)
    //    {
    //        if (initializationCallback != null)
    //            initializationCallback(widget, Descriptor);

    //        if (initializationCallback != null)
    //            _widgetsAndInitializationCallbackMapping[widget] = (obj, desc) => initializationCallback((TW) obj, desc);

    //        _widgetsAndCanExecuteCallbackMapping[widget] = (obj, canExecute) => canExecuteCallback((TW) obj, canExecute);
    //    }

    //    public void UnRegisterWidget(object widget)
    //    {
    //        if (_widgetsAndInitializationCallbackMapping.ContainsKey(widget))
    //            _widgetsAndInitializationCallbackMapping.Remove(widget);

    //        if (_widgetsAndCanExecuteCallbackMapping.ContainsKey(widget))
    //            _widgetsAndCanExecuteCallbackMapping.Remove(widget);
    //    }
    //    #endregion

    //    #region Protected Overrides

    //    protected override void OnCanExecuteChanged()
    //    {
    //        foreach (var canExecuteCallbackMapping in _widgetsAndCanExecuteCallbackMapping)
    //        {
    //            canExecuteCallbackMapping.Value(canExecuteCallbackMapping.Key, this.CanExecute);
    //        }
    //        base.OnCanExecuteChanged();
    //    }
    //    #endregion
    //}
}